﻿using Sustainalytics.Events.Exceptions;
using Sustainalytics.Events.Service.Errors;

namespace Sustainalytics.Events.Service.Map
{
    public class EventListOptionsValidationMapper
    {
        public static EventListOptionsValidationMapper Instance = new EventListOptionsValidationMapper();

        private int _failedValidationErrorCode = -1;
        private int _invalidPropertyNameCode = -1;
        public EventListOptionsValidationMapper()
        {
            this._failedValidationErrorCode = (int)EventsErrorCodes.EventsListOptions_FailedValidation;
            this._invalidPropertyNameCode = (int)EventsErrorCodes.EventsListOptions_InvalidPropertyName;
        }

        public ValidationErrorDto Map(InvalidPropertyNameException exception)
        {
            if (exception == null)
                return null;

            var errorDetails = new ValidationErrorDto(this._failedValidationErrorCode);

            errorDetails.Add(new InvalidPropertyNameResultDto
            {
                Code = _invalidPropertyNameCode,
                Property = exception.PropertyName,
                IsError = true
            }
            );
                
            return errorDetails;
        }
    }
}
